#!/usr/bin/env python
#
# Copyright (c) 2011 GhostBSD
#
# See COPYING for licence terms.
#
# gbi_user.py v 0.0 Tuesday, February 22 2011 10:54:53 Eric
#
# gbi_user.py create users and root password.

import pygtk
pygtk.require('2.0')
import gtk
import os, os.path, sys, stat, shutil

class users:
    def close_application(self, widget):
        os.system("killall python")
    
    def quit_application(self, widget):
        gtk.main_quit()		
    
    def create_bbox(self, horizontal, spacing, layout):
        frame = gtk.Frame()

        if horizontal:
            bbox = gtk.HButtonBox()
        else:
            bbox = gtk.VButtonBox()

        bbox.set_border_width(5)
        frame.add(bbox)

        # Set the appearance of the Button Box
        bbox.set_layout(layout)
        bbox.set_spacing(spacing)

        button = gtk.Button(stock=gtk.STOCK_GO_BACK)
        bbox.add(button)
        
        button = gtk.Button(stock=gtk.STOCK_CANCEL)
        bbox.add(button)

        button = gtk.Button(stock=gtk.STOCK_GO_FORWARD)
        bbox.add(button)
        button.connect("clicked", self.quit_application)
        return frame
    
    def __init__(self):
        window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        window.connect("destroy", self.close_application)
        window.set_size_request(550, 400)  
        window.set_title("GBI User Creation")
        window.set_border_width(0)
        window.set_position(gtk.WIN_POS_CENTER)

        try:
            window.set_icon_from_file("G-logo.png")
        except Exception, e:
            print e.message
            sys.exit(1)
        
        box1 = gtk.VBox(False, 0)
        window.add(box1)
        box1.show()

        box2 = gtk.VBox(False, 10)
        box2.set_border_width(10)
        box1.pack_start(box2, True, True, 0)
        box2.show()
        # password for root.
        frame = gtk.Frame("Administrator Password (root)")
        
        self.table = gtk.Table(1, 2, True)

        self.label1 = gtk.Label("Password")
        self.password = gtk.Entry()
        self.label2 = gtk.Label("Verify Password")
        self.repassword = gtk.Entry()

        self.table.attach(self.label1, 0, 1, 0, 1)
        self.table.attach(self.password, 1, 2, 0, 1)
        self.table.attach(self.label2, 2, 3, 0, 1)
        self.table.attach(self.repassword, 3, 4, 0, 1)

        frame.add(self.table)
        box2.pack_start(frame, False, False, 0)  
        
        frame = gtk.Frame("Add User")
        
        self.table = gtk.Table(1, 2, True)
        
        self.label1 = gtk.Label("Username")
        self.user = gtk.Entry()
        self.label2 = gtk.Label("Full Name")
        self.name = gtk.Entry()
        self.label3 = gtk.Label("Password")
        self.password = gtk.Entry()
        self.label4 = gtk.Label("Verify Password")
        self.repassword = gtk.Entry()
        self.label5 = gtk.Label("Shell")
        self.shell = gtk.ComboBox()
        
        self.table.attach(self.label1, 0, 1, 0, 1)
        self.table.attach(self.user, 1, 2, 0, 1)
        self.table.attach(self.label2, 2, 3, 0, 1)
        self.table.attach(self.name, 3, 4, 0, 1)
        self.table.attach(self.label3, 0, 1, 1, 2)
        self.table.attach(self.password, 1, 2, 1, 2)
        self.table.attach(self.label4, 2, 3, 1, 2)
        self.table.attach(self.repassword, 3, 4, 1, 2)
        self.table.attach(self.label5, 0, 1, 2, 3)
        self.table.attach(self.shell, 1, 2, 2, 3)

        
        frame.add(self.table)
        box2.pack_start(frame, False, False, 0)
        
        box2 = gtk.HBox(False, 10)
        box2.set_border_width(5)
        box1.pack_start(box2, False, True, 0)
        box2.show()

        
        
        box2.pack_start(self.create_bbox(True,
                                         10, gtk.BUTTONBOX_END),
                        True, True, 5)
        window.show_all ()
        
        
         
def main():
    gtk.main()
    return 0

if __name__ == "__main__":
    users()
    main()
